package com.fulihui.usercore.enums;

import org.near.toolkit.model.BaseEnum;

/**
 * 布尔值枚举，中文、代码、true/false的绑定关系
 * Created by Willard.Hu on 2016/5/19.
 */
public enum BooleanValueEnum implements BaseEnum {

    TRUE("1", true, "真"),

    FALSE("0", false, "假"),

    ;

    private String  code;
    private boolean value;
    private String  desc;

    BooleanValueEnum(String code, boolean value, String desc) {
        this.code = code;
        this.value = value;
        this.desc = desc;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDesc() {
        return desc;
    }

    public boolean isTrue() {
        return value;
    }

    public static BooleanValueEnum byBoolean(boolean b) {
        BooleanValueEnum[] enums = BooleanValueEnum.values();
        for (BooleanValueEnum e : enums) {
            if (e.isTrue() == b) {
                return e;
            }
        }
        throw new IllegalArgumentException("Not exists");
    }

    public static BooleanValueEnum byCode(String code) {
        BooleanValueEnum[] enums = BooleanValueEnum.values();
        for (BooleanValueEnum e : enums) {
            if (e.getCode().equals(code)) {
                return e;
            }
        }
        throw new IllegalArgumentException("Not exists, code:" + code);
    }
}
